package a66weding.com.jiehuntong.pager;

import android.app.Activity;
import android.content.Intent;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import a66weding.com.jiehuntong.R;

/**
 * 各个页面的基类
 *
 */
public abstract class BasePager {

    public boolean mInit;
    public View mRootView;
    public static Activity mActivity;
    public PopupWindow mCommitpop;
    protected static final int HAVEDATA=1;
    protected static final int NODATA=0;
    protected static final int DATAERROR=2;
    protected static final int NONET=3;

    public BasePager(Activity activity) {
        mActivity = activity;
        mRootView = getView();
    }
    /**
     * 获取当前详情页面视图, 强制子类实现
     */
    protected abstract View getView();
    /**
     * 初始化方法, 留给子类实现, 在页面加载后调用
     */
    public void initData() {}
    public void notifyData(){}
    public void onResumePager(){};
    public void destroyPager(){}
    public void onActivityResult(int requestCode, int resultCode, Intent data) {}
    public void showCommitPopupWindow(View view) {
        // 一个自定义的布局，作为显示的内容
        View contentView = LayoutInflater.from(mActivity).inflate(
                R.layout.pop_tools_wedregister_commit, null);
        mCommitpop = new PopupWindow(contentView,
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
        //点击空白处时，隐藏掉pop窗口
        mCommitpop.setTouchable(true);
        mCommitpop.setTouchInterceptor(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
                // 这里如果返回true的话，touch事件将被拦截
                // 拦截后 PopupWindow的onTouchEvent不被调用，这样点击外部区域无法dismiss
            }
        });

        //设置位置
        mCommitpop.showAtLocation(view, Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL,0,0);//设置在屏幕中的显示位置
        // 设置好参数之后再show
        mCommitpop.showAsDropDown(view);
    }
}
